#ifndef INCLUDE_SNMPTYPE_H
#define INCLUDE_SNMPTYPE_H

#ifndef SNMP_WANTED
#define SNMP_WANTED       1
#endif

#ifndef SNMP_TRAP
#define SNMP_TRAP         1
#endif

#ifndef GET_BULK_SUPPORT
#define GET_BULK_SUPPORT  1
#endif

#ifndef TRAP_SVR_LEARN_EN
#define TRAP_SVR_LEARN_EN 0
#endif

#ifndef MAX_SUPPORT_OID_NUM
#define MAX_SUPPORT_OID_NUM 10  /*10*/
#endif

#ifndef MAX_OCTET_LENGTH
#define MAX_OCTET_LENGTH   	128/*512*/
#endif

#ifndef MAX_OID_LENGTH
#define MAX_OID_LENGTH		20  /*20*/
#endif

#ifndef MAX_OID_PREFIX_SIZE
#define MAX_OID_PREFIX_SIZE		16  /*20*/
#endif

#ifndef TRAP_USE_COMMUNITY
#define TRAP_USE_COMMUNITY 0
#endif

#ifndef ENTERPRISE_OID
#define ENTERPRISE_OID 9999
#endif

#ifndef DEVICE_ID
#define DEVICE_ID 1
#endif

#ifndef DEVICE_DESCR
#define DEVICE_DESCR "MCU SNMP Agent"
#endif

#ifndef DEVICE_NAME
#define DEVICE_NAME "MCU SNMP Agent"
#endif

#ifndef MAX_TRAP_SERVER_NUM
#define MAX_TRAP_SERVER_NUM 2
#endif

#ifndef MAX_COMMUNITY_NUM
#define MAX_COMMUNITY_NUM 	2
#endif

#define MAX_COMMUNITY_LEN 	16


#define OCTETS_PER_INT32    4
#define OCTETS_PER_INT16    2

typedef signed char    _INT8;   /*signed 8 bit definition*/
typedef unsigned char   _UINT8;   /*unsigned 8 bit definition*/
typedef signed short   _INT16;   /*signed 16 bit definition*/
typedef unsigned short _UINT16;   /*unsigned 16 bit definition*/
typedef signed int     _INT32;   /*signed 32 bit definition*/
typedef unsigned int _UINT32;   /*unsigned 32 bit definition*/

#define LWORD	unsigned long		/**< 32 bit unsigned */
#define BYTE 	unsigned char
#define WORD 	unsigned short		/**< 16 bit unsigned */

#define UINT8	unsigned char		/**< 8 bit unsigned */
#define INT8	signed char			/**< 8 bit signed */
#define UINT16	unsigned short		/**< 16 bit unsigned */
#define INT16	signed short				/**< 16 bit signed */
#define UINT32	unsigned int		/**< 16 bit unsigned */
#define INT32	signed int				/**< 16 bit signed */
//#define	ntohl(x)	(x)
//#define	ntohs(x)	(x)
//#define	htonl(x)	(x)
//#define	htons(x)	(x)

#ifndef ntohl
#define ntohl(x)	((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) <<  8) | \
			 (((x) & 0x00ff0000) >>  8) | (((x) & 0xff000000) >> 24))

#define htonl(x)	((((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) <<  8) | \
			 (((x) & 0x00ff0000) >>  8) | (((x) & 0xff000000) >> 24))

#define ntohs(x)	((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))

#define htons(x)	((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
#endif


#define V_BIT0 0x01
#define V_BIT1 0x02
#define V_BIT2 0x04
#define V_BIT3 0x08
#define V_BIT4 0x10
#define V_BIT5 0x20
#define V_BIT6 0x40
#define V_BIT7 0x80


#define OID_LEN(oid) (sizeof(oid)/sizeof(_UINT32))

typedef struct
{
	_UINT32 high;			/* the high (msb) 4 bytes of the uint */
	_UINT32 low;			/* the low (lsb) 4 bytes of the uint  */
} UINT64_T;

typedef struct
{
	_UINT8 num_components;
	_UINT32 component_list[MAX_OID_LENGTH];
} OBJ_ID_T;

typedef struct
{
	_UINT16 vb_seq_size;/* Overall length of the VarBind*/
	OBJ_ID_T vb_obj_id;	/* Object id for this VarBind */
	_UINT16 defined_prefix_len;
	_UINT16 defined_index_cnt;
	_UINT32 *pLeafId;
	_UINT32 *pIndex;
	_INT16(*process)(_UINT8 request,void *vbp);
	_UINT8 vb_data_flags_n_type;/*Class form & type of data */
	_UINT8 vb_flags;			/*See below*/
	_UINT16 vb_data_length;	/*Length of the sending data when encode */
	union
	{
		_INT32 v_number;		/*Integer kinds of things  */
		_UINT32 v_counter;	/*Unsigned int things*/
		_UINT8 v_string[MAX_OCTET_LENGTH];	/* Octetstring things       */
		OBJ_ID_T v_object;	/* Object id things         */
		_UINT8 v_network_address[4];
		UINT64_T v_counter64;	/* 64 bit unsigned things   */
	} value_u;
} VB_T;

typedef struct
{
	_UINT16   type;
	_UINT32   prefixSubOid[MAX_OID_PREFIX_SIZE];
	_UINT16   prefixLen;
	_UINT16   idxCnt;
	_UINT16   leafNum;
	_INT16(*pObjHandler)(_UINT8 request,VB_T *vbp);
} SNMP_OID_TABLE_T;

typedef struct
{
	_UINT32 snmpInPkts;
	_UINT32 snmpInBadVersions;
	_UINT32 snmpInBadCommunityNames;
	_UINT32 snmpInBadCommunityUses;
	_UINT32 snmpInASNParseErrs;
	_UINT16 snmpEnableAuthTraps;
	_UINT32 snmpOutPkts;
	_UINT32 snmpInBadTypes;
	_UINT32 snmpInTooBigs;
	_UINT32 snmpInNoSuchNames;
	_UINT32 snmpInBadValues;
	_UINT32 snmpInReadOnlys;
	_UINT32 snmpInGenErrs;
	_UINT32 snmpInTotalReqVars;
	_UINT32 snmpInTotalSetVars;
	_UINT32 snmpInGetRequests;
	_UINT32 snmpInGetNexts;
	_UINT32 snmpInSetRequests;
	_UINT32 snmpInGetResponses;
	_UINT32 snmpInTraps;
	_UINT32 snmpOutTooBigs;
	_UINT32 snmpOutNoSuchNames;
	_UINT32 snmpOutBadValues;
	_UINT32 snmpOutReadOnlys;
	_UINT32 snmpOutGenErrs;
	_UINT32 snmpOutGetRequests;
	_UINT32 snmpOutGetNexts;
	_UINT32 snmpOutSetRequests;
	_UINT32 snmpOutGetResponses;
	_UINT32 snmpOutTraps;
	_UINT32 snmpSilentDrops;
	_UINT32 snmpProxyDrops;
} SNMP_STATS_T;

typedef struct
{
	_UINT32 addr;
#if TRAP_USE_COMMUNITY==1
	_UINT8 community[MAX_COMMUNITY_LEN];
#endif
	_UINT16 port;
	_UINT16 enable;
} TRAP_SERVER_T;

typedef struct
{
	_UINT8 name[MAX_COMMUNITY_LEN];
	_UINT32 ability;
} COMMUNITY_T;

typedef struct
{
	_UINT16 snmp_family;
	_UINT8  snmp_data[16];
	_UINT16  snmp_port;
} SNMPADDR_T;

typedef struct
{
	_UINT16 error_status;
	_UINT16 error_index;
} SNMP_ERR_T;

typedef struct
{
	_UINT16 generic;
	_UINT16 specfic;
} SNMP_TRAP_T;


typedef struct
{
	_UINT32 sochandle;
	_UINT32 remip;
	_UINT16 remport;
	_INT8 state;
	_UINT8  community[MAX_COMMUNITY_LEN];
	_UINT8 *outbuf;
	_UINT16 maxOutLen;
	_UINT8  pdu_type;
	_UINT8 snmp_version;
	_UINT16 overall_length; /* Message Sequence length */
	_UINT16 pdu_length;
	_UINT32 localip;
	_UINT32 timestamp;
	struct
	{
		_UINT32 request_id;
		union
		{
			SNMP_TRAP_T trapID;
			SNMP_ERR_T errID;
		} ext;
		_INT16 non_rep;
		_INT16 max_rep;
		_UINT16 vbl_length;
		_UINT16 vb_count;
		VB_T  vb_obj[MAX_SUPPORT_OID_NUM];
	} pdu;
} SNMP_PKT_T;

typedef struct
{
	_UINT8 state;
	_INT8 sochandle;
	_UINT32 remip;
	_UINT16 remport;
} SNMP_T;

#endif
